﻿#region

using System;
using System.IO;
using System.Text.RegularExpressions;

#endregion


namespace OMS.Ice.T4Generator.Syntax
{
    internal class IncludeDirective : Directive
    {
        public IncludeDirective(Match match, MacroResolver macroResolver)
            : base( match, macroResolver )
        {
        }

        public string File
        {
            get { return Attributes["file"]; }
        }

        public string Name
        {
            get { return Path.GetFileNameWithoutExtension( File ); }
        }

        public IncludeMode Mode
        {
            get
            {
                if( !Attributes.ContainsKey( "mode" ) )
                    return IncludeMode.Inline;

#if !FRAMEWORK35
                IncludeMode mode;
                return Enum.TryParse( Attributes["mode"], true, out mode ) ? mode : IncludeMode.Inline;
#else
                try
                {
                    return (IncludeMode)Enum.Parse(typeof(IncludeMode), Attributes["mode"], true);
                }
                catch
                {
                    return IncludeMode.Inline;
                }
#endif
            }
        }

        public override bool Equals( object obj )
        {
            var toCompare = obj as IncludeDirective;

            return toCompare != null && Name.Equals( toCompare.Name ) && Mode.Equals( toCompare.Mode );
        }

        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }
    }
}